useSSR
☯️ React hook to determine if you are on the server, browser, or react native
Need to know when you're on the server, in the browser or in react native in your components/hooks? This simple hook makes it easy. 🔥
Features
- SSR (server side rendering) support
- TypeScript support
- Zero dependencies
- React Native support
Examples
Installation
yarn add use-ssr or npm i -S use-ssr
Usage
import useSSR from 'use-ssr'
const App = () => {
var { isBrowser, isServer, isNative } = useSSR()
var [isBrowser, isServer, isNative] = useSSR()
console.log('IS BROWSER: ', isBrowser ? '👍' : '👎')
console.log('IS SERVER: ', isServer ? '👍' : '👎')
console.log('IS NATIVE: ', isNative ? '👍' : '👎')
return (
<>
Is in browser? {isBrowser ? '👍' : '👎'}
<br />
Is on server? {isServer ? '👍' : '👎'}
<br />
Is react native? {isNative ? '👍' : '👎'}
</>
)
}
Options
const {
isBrowser,
isServer,
isNative,
device,
canUseWorkers,
canUseEventListeners,
canUseViewport,
} = useSSR()
const [
isBrowser,
isServer,
isNative,
device,
canUseWorkers,
canUseEventListeners,
canUseViewport,
] = useSSR()
Todos